#ifndef __CMODEL_FLOAT_H__
#define __CMODEL_FLOAT_H__
#include <stdio.h>
#include <stdlib.h>

// #define USE_INT16

#ifndef DEBUG
#define DEBUG 1
#endif

#define MAX_MEM_POOL_SIZE 40000 // 最大使用40K单位数组作为缓冲

// 头文件汇总
#include "conv2d.h"
#include "dataLoadSave.h"
#include "mat_add.h"
#include "avg_pool2d.h"

#include "conv2d_acc.h"

// 函数宏
#ifdef EMBEDDED
    // TODO: 适用于单片机的动态内存分配
#else
    #define MEM_ALLOC(size) malloc(size)
    #define MEM_FREE(ptr) free(ptr)
#endif

#define debug(...) {if (DEBUG){printf("@["__FILE__":%d] ",__LINE__);printf(__VA_ARGS__);}}

#define emptyFeatureMap(img, c, w, h) ({\
    img.channels = c;\
    img.width = w;\
    img.height = h;\
    img.data = (DTYPE *)MEM_ALLOC(c*w*h * sizeof(DTYPE));\
    for (int i = 0; i < c*w*h; i++)\
        img.data[i] = 0.0;\
    c*w*h;\
})

#define printFeatureMap(img){\
    for (int i = 0; i < img.width; i++)\
    {\
        for (int j = 0; j < img.height; j++)\
        {\
            printf(#img"[%d][%d]=%d, ",i, j, img.data[i*img.height + j]);\
        }\
        printf("\n");\
    }\
}


#define POW2(a) ((a)*(a))
#define ABS(a) ((a)>0?(a):-(a))
#define RelU(x) ((x) < 0.0 ? (0.0) : (x))

#ifdef USE_INT16
    #define RelU6(x) ((x) < 0 ? (0) : (x) < 6*256 ? (x) : 6*256)
#else
    #define RelU6(x) ((x) < 0.0 ? (0.0) : (x) < 6.0 ? (x) : 6.0)
#endif // USE_INT16
#endif // __CMODEL_FLOAT_H__
